package tronglv.gs.model;

import org.andengine.opengl.texture.region.TiledTextureRegion;

import tronglv.gs.control.ResourcesManager;

public class Jewel {

	int x, y, xLast, yLast;
	boolean isSelect = false;
	ResourcesManager resourcesManager;
	boolean isEaten;
	int typeJewel;


	

	public Jewel(int x, int y) {
		this.x = x;
		this.y = y;
		this.xLast =x;
		this.yLast = y;
	}
	public int getTypeJewel() {
		return typeJewel;
	}

	public void setTypeJewel(int typeJewel) {
		this.typeJewel = typeJewel;
	}

	public boolean getIsEated() {
		return isEaten;
	}

	public void setIsEated(boolean isEaten) {
		this.isEaten = isEaten;
	}

	public int getX() {
		return x;
	}

	public void setX(int x) {
		setxLast(this.x);
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		setyLast(this.y);
		this.y = y;
	}

	public int getxLast() {
		return xLast;
	}

	public void setxLast(int xLast) {
		this.xLast = xLast;
	}

	public int getyLast() {
		return yLast;
	}

	public void setyLast(int yLast) {
		this.yLast = yLast;
	}

	// di chuyen quan sang trai 1 buoc
	private void moveLeft() {
		xLast = x;

		x--;
	}

	// di chuyen quan sang phai 1 buoc
	private void moveRight() {
		xLast = x;

		x++;
	}

	// di chuyen quan len tren 1 buoc
	private void moveUp() {
		yLast = y;

		y--;
	}

	// di chuyen quan sang trai 1 buoc
	private void moveDown() {
		yLast = y;

		y++;
	}

	public boolean swap(Jewel other) {
		// neu other o tren
		if (other.getX() == x && other.getY() == y - 1) {
			other.moveDown();
			this.moveUp();

			return true;
		}

		// neu other o duoi
		if (other.getX() == x && other.getY() == y + 1) {
			other.moveUp();
			this.moveDown();

			return true;
		}

		// neu other ben trai
		if (other.getY() == y && other.getX() == x - 1) {
			other.moveRight();
			this.moveLeft();

			return true;
		}

		// neu other ben phai
		if (other.getY() == y && other.getX() == x + 1) {
			other.moveLeft();
			this.moveRight();

			return true;
		}

		return false;
	}

}
